<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据来源">
              <j-dict-select-tag placeholder="请选择单据来源" @input="handleDocumentSource" v-model="queryParam.permissionType" dictCode="permission_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 3">
            <a-form-item label="选择部门">
              <J-select-multiple
                placeholder="请选择选择部门"
                :options="getDepartName"
                showId="id"
                v-model="queryParam.deptIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 4">
            <a-form-item label="选择团队">
              <J-select-multiple
                placeholder="请选择选择团队"
                :options="getTeamName"
                showId="id"
                v-model="queryParam.teamIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号" class="form-item">
              <a-input placeholder="请输入单据编号" v-model="queryParam.ptzhbm"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="会员单位" class="form-item">
              <a-input placeholder="请输入会员单位" v-model="queryParam.hydw"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="平台名称" class="form-item">
              <a-input placeholder="请输入平台名称" v-model="queryParam.ptmc"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="网址" class="form-item">
              <a-input placeholder="请输入网址" v-model="queryParam.wz"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请类型">
              <j-dict-select-tag placeholder="请选择申请类型" v-model="queryParam.lx" dictCode="lx_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="保管人">
              <select-user-by-dep :multi="false" v-model="queryParam.bgr" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep :multi="false" v-model="queryParam.proposer" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType != 3">
            <a-form-item label="申请部门" class="form-item">
              <j-select-depart v-model="queryParam.proposerDeptId"/>
            </a-form-item>
          </a-col>
          <a-col :xl="9" :lg="7" :md="8" :sm="24">
            <a-form-item label="会员有效期始" class="form-item">
              <a-date-picker
                placeholder="请选择开始时间"
                @change="handleChange"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                v-model="queryParam.hyyxqs_begin"
                style="width: 47%" />
              <span class="fontDiy"> 至 </span>
              <a-date-picker
                :disabled-date="disabledDate"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                :default-picker-value="this.queryParam.hyyxqs_begin"
                placeholder="请选择结束时间"
                v-model="queryParam.hyyxqs_end"
                style="width: 47%" />
            </a-form-item>
          </a-col>
          <a-col :xl="9" :lg="7" :md="8" :sm="24">
            <a-form-item label="会员有效期止" class="form-item">
              <a-date-picker
                placeholder="请选择开始时间"
                @change="handleChangeNew"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                v-model="queryParam.hyyxqe_begin"
                style="width: 47%" />
              <span class="fontDiy"> 至 </span>
              <a-date-picker
                :disabled-date="disabledDateNew"
                format="YYYY-MM-DD"
                valueFormat="YYYY-MM-DD"
                :default-picker-value="this.queryParam.hyyxqe_begin"
                placeholder="请选择结束时间"
                v-model="queryParam.hyyxqe_end"
                style="width: 47%" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="allSearchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpOmcPlatformAccount:add')">
        建档申请
      </a-button>
      <a-button @click="handleAdd2" type="primary" icon="plus" :disabled="isDisabledAuth('erpOmcPlatformAccount:add')">
        变更申请
      </a-button>
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('平台账号管理')"-->
      <!--                :disabled="isDisabledAuth('erpOmcPlatformAccount:export')">导出-->
      <!--      </a-button>-->
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
      <!--                @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOmcPlatformAccount:import')">导入</a-button>-->
      <!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcPlatformAccount:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">
                      <ellipsis :length="15">{{ item.title }}</ellipsis>
                    </a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps: (record) => { return { props: { disabled: record.bpmStatus !== '1' } } }}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="ptzhbm" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <span slot="notify" slot-scope="text, record">
          <a-icon
            title="催办提醒"
            v-if="record.taskUrge"
            theme="twoTone"
            twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode,record.id)"
            type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="record.bpmStatus === '1'">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpOmcPlatformAccount:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpOmcPlatformAccount:delete')"/>
            </a-popconfirm>
            <!-- <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="beginProcess(record)"
                      :disabled="isDisabledAuth('erpOmcPlatformAccount:startProcess')">发起流程</a-button> -->
          </template>
          <!--        <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">-->
          <!--            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>-->
          <!--            <a-divider type="vertical"/>-->
          <!--        </template>-->
          <!--        <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
                <a-button type="primary" size="small"
                          :disabled="isDisabledAuth('erpOmcPlatformAccount:invalidProcess')">
                    作废流程
                </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
        </template>-->
          <template v-if="record.bpmStatus !== '1'">
            <a-button
              type="primary"
              size="small"
              @click="handleTrack(record)"
              :disabled="isDisabledAuth('erpOmcPlatformAccount:viewTrack')">审批进度</a-button>
          </template>
        </span>
        <span slot="modelAndViewRender" slot-scope="text">
          <j-ellipsis :value="text" :length="10"/>
        </span>
      </a-table>
    </div>
    <process-config-modal ref="processConfig" @ok="handleSuccess" @close="handleClose"></process-config-modal>
    <erp-omc-platform-account-modal ref="modalForm" @ok="modalFormOk"></erp-omc-platform-account-modal>
    <bpm-biz-task-deal-modal
      ref="taskDealModal"
      :path="path"
      :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpOmcPlatformAccountModal from './modules/ErpOmcPlatformAccountModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import moment from 'moment';
import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
import Ellipsis from '@/components/Ellipsis'
import { getAction } from '../../../../api/manage';
import TrendVue from '../../../../components/Trend/Trend.vue';
export default {
  name: 'ErpOmcPlatformAccountList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcPlatformAccountModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectUserByDep,
    ProcessConfigModal,
Ellipsis
  },
  data() {
    return {
      description: '平台账号管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      queryParam: {
        bizTaskType: '2'
      },
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'ptzhbm',
          width: 180,
          ellipsis: true,
          scopedSlots: { customRender: 'ptzhbm' }
        },
        {
          title: '会员单位',
          align: 'center',
          dataIndex: 'hydw',
          width: 166,
          ellipsis: true
        },
        {
          title: '平台名称',
          align: 'center',
          dataIndex: 'ptmc',
          width: 166,
          ellipsis: true
        },
        {
          title: '网址',
          align: 'center',
          dataIndex: 'wz',
          width: 160,
          ellipsis: TrendVue
        },
        {
          title: '保管人',
          align: 'center',
          dataIndex: 'bgr_dictText',
          width: 90,
          ellipsis: true
        },
        {
          title: '登录名',
          align: 'center',
          dataIndex: 'dlm',
          width: 100,
          ellipsis: true
        },
        {
          title: '密码',
          align: 'center',
          dataIndex: 'mm',
          width: 100,
          ellipsis: true
        },
        {
          title: '会员等级',
          align: 'center',
          dataIndex: 'hydj',
          width: 80,
          ellipsis: true
        },
        {
          title: 'ca锁密码',
          align: 'center',
          dataIndex: 'casmm',
          width: 90,
          ellipsis: true
        },
        {
          title: 'ca锁个数',
          align: 'center',
          dataIndex: 'casgs',
          width: 90,
          ellipsis: true
        },
        {
          title: '会员有效期始',
          align: 'center',
          dataIndex: 'hyyxqs',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          width: 101,
          ellipsis: true
        },
        {
          title: '会员有效期止',
          align: 'center',
          dataIndex: 'hyyxqe',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          width: 101,
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
          width: 60,
          ellipsis: true
        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'proposerDeptId_dictText',
          width: 130,
          ellipsis: true
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          width: 60,
          ellipsis: true
        },
        {
          title: '申请类型',
          align: 'center',
          dataIndex: 'lx_dictText',
          width: 80,
          ellipsis: true
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 150,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/list',
        delete: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/delete',
        deleteBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/deleteBatch',
        exportXlsUrl: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/exportXls',
        importExcelUrl: 'api/erp/omc/platformaccount/erpOmcPlatformAccount/importExcel',
        bizCount: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/bizCount',
        updateStatus: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/updateStatus'
      },
      // 代码生成后需手动设置流程编码
      flowCode: 'dev_erp_omc_platform_account_001',
      formUrl: 'erp/omc/platformaccount/modules/ErpOmcPlatformAccountForm',
      beanName: 'erpOmcPlatformAccountServiceImpl',
      formUrlMobile: '/pages/synergy/erpOmcPlatformAccountList',
      dictOptions: {},
      superFieldList: [],
      processId: '1470356704918040578',
      lx: 1
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    allSearchReset() {
      this.qdrqRange = null
      this.queryParam = { permissionType: '1' };
      this.queryParam.bizTaskType = '2';
      this.bizTaskType = null
      this.loadData(1);
    },
    beginProcess(record) {
      // 发起前判断是不是变更 修改变更状态
      if (record.lx == 2) {
        // 修改为变更中
        getAction(this.url.updateStatus, { code: record.ptzhbm }).then(res => {
          if (res.code == 200) {
            this.$refs.processConfig.visible = true
            this.$refs.processConfig.formUrl = this.formUrl
            this.$refs.processConfig.formUrlMobile = this.formUrlMobile
            this.$refs.processConfig.flowCode = this.flowCode
            this.$refs.processConfig.edit(record, this.processId, this.beanName)
          } else {
            this.$message.warning(res.message)
            this.handleClose()
          }
        })
      } else {
        this.$refs.processConfig.visible = true
        this.$refs.processConfig.formUrl = this.formUrl
        this.$refs.processConfig.formUrlMobile = this.formUrlMobile
        this.$refs.processConfig.flowCode = this.flowCode
        this.$refs.processConfig.edit(record, this.processId, this.beanName)
      }
    },
    // 查看详情
    getDetail(id) {
      this.$router.push({
        path: `/erp/omc/platformaccount/ErpOmcPlatformAccountListDetail/${id}`
      })
    },
    handleAdd: function () {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    handleAdd2: function () {
      this.$refs.modalForm.add2()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'ptmc', text: '平台名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'hydw', text: '会员单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'wz', text: '网址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dlm', text: '登录名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'mm', text: '密码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'hydj', text: '会员等级', dictCode: '' })
      fieldList.push({ type: 'date', value: 'hyyxqs', text: '会员有效期始' })
      fieldList.push({ type: 'date', value: 'hyyxqe', text: '会员有效期止' })
      fieldList.push({ type: 'string', value: 'casmm', text: 'ca锁密码', dictCode: '' })
      fieldList.push({ type: 'int', value: 'casgs', text: 'ca锁个数', dictCode: '' })
      fieldList.push({ type: 'date', value: 'casyxqs', text: 'ca锁有效期始' })
      fieldList.push({ type: 'date', value: 'casyxqe', text: 'ca锁有效期止' })
      fieldList.push({ type: 'string', value: 'bz', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jbr', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jbbm', text: '经办部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleChange(value) {
      if (this.queryParam.insuranceEndTime) {
        if ((this.queryParam.insuranceEndTime).diff((this.queryParam.hyyxqs_begin), 'days') < 0) {
          this.queryParam.insuranceEndTime = this.queryParam.hyyxqs_begin
        }
      }
    },
    disabledDate(current) {
      return current < moment(this.queryParam.hyyxqs_begin).subtract('day')
    },
    handleChangeNew(value) {
      if (this.queryParam.insuranceEndTime) {
        if ((this.queryParam.insuranceEndTime).diff((this.queryParam.hyyxqe_begin), 'days') < 0) {
          this.queryParam.insuranceEndTime = this.queryParam.hyyxqe_begin
        }
      }
    },
    disabledDateNew(current) {
      return current < moment(this.queryParam.hyyxqe_begin).subtract('day')
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
